package cn.fjsay.java.demo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class JdbcDemo3 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/persondb","root","root");
            System.out.println(conn == null ? "连接失败" : "连接成功");

            String sql = "delete from t_person where pid=?";
            PreparedStatement psmt = conn.prepareStatement(sql);
            psmt.setInt(1, 4);//x就是要删除的id

            int count =psmt.executeUpdate();
            System.out.println(count>0?"删除成功":"删除失败");

            psmt.close();
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }
}
